<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>留言列表</title>
<link href="/tmx/css/common.css" rel="stylesheet" />
<script type="text/javascript" src="/tmx/js/jquery-1.8.1.min.js"></script>
<script type="text/javascript">
function searchMessage(){
	var content = $.trim($('#content').val());
	$('#check').val(content);
	ajaxMessage(1);
}

function firstPage(){
	ajaxMessage(1);
}

function prevPage(){
	var start =parseInt($("#start").html());
	if(start <= 1){
		start = 1;
	}else{
		start--;
	}
	ajaxMessage(start);
}

function nextPage(){
	var start =parseInt($("#start").html());
	var count = parseInt($("#pageCount").html());
	if(start >= count){
		start = count;
	}else{
		start++;
	}
	ajaxMessage(start);
}

function endPage(){
	var last = parseInt($("#pageCount").html());
	ajaxMessage(last);
}

function goPage(){
	var start = parseInt($("#go").val());
	var reg =  /^[0-9]*[1-9][0-9]*$/ ;
	var count = parseInt($("#pageCount").html());
	if (!reg.test(start)) {
		alert("请输入正确的数字！");
		return false;
	}
	if(start > count){
		alert("请输入正确的数字！");
		return false;
	}
	ajaxMessage(start);
}

function ajaxMessage(start){
	var content = $.trim($('#check').val());
	$.ajax({
		url:'${pageContext.request.contextPath}/MessageAction!searchMessageList.action',
		data:{
			"page.currPage":start,
			"message.content":content
		},
		type:'post',
		dataType:'json',
		success:function(data){
			var str="";
			if(data.map.length>0){
				$.each(data.map,function(i){
					str+='<tr><td  class="h30 bot column7_1 bR">'+data.map[i].index+
					'</td><td  class="h30 bot column7_1 bR">'+data.map[i].content+
					'</td><td  class="h30 bot column7_1 bR">'+data.map[i].name+
					'</td><td  class="h30 bot column7_1 bR">'+data.map[i].phone+
					'</td><td  class="h30 bot column7_1 bR">'+data.map[i].date+
					'</td><td  class="h30 bot column7_1"><a href="javascript:void(0)" onclick="showMessage('+data.map[i].timeKey+')">详细</a></td></tr>';
				});
			}
			$("#nodeContent").html(str);
			$("#start").html(data.object.currPage);
			$("#pageCount").html(data.object.pageCount);
		}
	});
}
function newNotice(){
}
function showMessage(timeKey){
	location.href="/tmx/MessageAction!showMessage.action?message.timeKey="+timeKey;
}
function delNotice(timeKey){
}
</script>
</head>
<body>
<div class="content">
  <div class="contentTitle">
    <div class="titImg"></div>
    留言管理</div>
  <table cellpadding="0" cellspacing="0" border="0" width="100%">
    <tr>
      <td class="bg bot bR" width="25%">内容：</td>
      <td class="bR bot align" width="30%"><input class="nInput" id="content"/></td>
      <td class="bot" width="45%">
      	<a class="operator" href="javascript:void(0)" onclick="searchMessage()">查询</a>
      </td>
    </tr>
  </table>
  <table cellpadding="0" cellspacing="0" border="0" width="100%">
    <tr>
      <th class="bg h30 bot column7_1 bR">序号</th>
      <th class="bg h30 bot column7_1 bR">内容</th>
      <th class="bg h30 bot column7_1 bR">姓名</th>
      <th class="bg h30 bot column7_1 bR">手机号</th>
      <th class="bg h30 bot column7_1 bR">添加时间</th>
      <th class="bg h30 bot column7_1">操作</th>
    </tr>
    <tbody id="nodeContent">
    <s:iterator value="messageList" var="m" status="statu">
    <tr >
      <td  class="bR bot column7_1 h30">${statu.index+1 }</td>
      <td  class="bR bot column7_1 h30">${m.content}</td>
      <td  class="bR bot column7_1 h30">${m.name}</td>
      <td  class="bR bot column7_1 h30">${m.phone}</td>
      <td  class="bR bot column7_1 h30"><s:date name="#m.createDate" format="yyyy-MM-dd HH:mm:ss"/></td>
      <td  class="bR bot column7_1 h30"><a href="javascript:void(0)" onclick="showMessage(${m.timeKey})">详细</a></td>
    </tr>
    </s:iterator>
    </tbody>
  </table>
<div class="page">
					<input id="check" value="" type="hidden"/>
						当前第<span id="start">${page.currPage}</span>页,共<span id="pageCount">${page.pageCount}</span>页<a
							href="javascript:;" onclick="firstPage()">首页</a><a
							href="javascript:;" onclick="prevPage()">上一页</a><a
							href="javascript:;" onclick="nextPage()">下一页</a><a
							href="javascript:;" onclick="endPage()">尾页</a>&nbsp;&nbsp;&nbsp;&nbsp;跳转到<input
							type="text" class="shotInput" id="go" />页<input type="button"
							value="Go" class="go" onclick="goPage()" />
					</div>
</div>
</body>
</html>
